package com.ruoyi.kindergarten.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.kindergarten.domain.ClassInfo;
import com.ruoyi.kindergarten.domain.Student;
import com.ruoyi.kindergarten.mapper.ClassInfoMapper;
import com.ruoyi.kindergarten.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.kindergarten.mapper.AttendanceLogMapper;
import com.ruoyi.kindergarten.domain.AttendanceLog;
import com.ruoyi.kindergarten.service.IAttendanceLogService;

/**
 * 入离园日志信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-26
 */
@Service
public class AttendanceLogServiceImpl implements IAttendanceLogService 
{
    @Autowired
    private AttendanceLogMapper attendanceLogMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private ClassInfoMapper classInfoMapper;


    /**
     * 查询入离园日志信息
     * 
     * @param id 入离园日志信息主键
     * @return 入离园日志信息
     */
    @Override
    public AttendanceLog selectAttendanceLogById(Long id)
    {
        AttendanceLog attendanceLog = attendanceLogMapper.selectAttendanceLogById(id);
        Student student = studentMapper.selectStudentById(attendanceLog.getStudentId());
        if (student != null) {
            attendanceLog.setStudentName(student.getName());
            attendanceLog.setAge(student.getAge());
            attendanceLog.setStudentNo(student.getStudentNo());
        }
        ClassInfo classInfo = classInfoMapper.selectClassInfoById(attendanceLog.getClassId());
        if (classInfo != null) {
            attendanceLog.setClassName(classInfo.getClassName());
        }
        return attendanceLog;
    }

    /**
     * 查询入离园日志信息列表
     * 
     * @param attendanceLog 入离园日志信息
     * @return 入离园日志信息
     */
    @Override
    public List<AttendanceLog> selectAttendanceLogList(AttendanceLog attendanceLog)
    {
        List<AttendanceLog> attendanceLogList = attendanceLogMapper.selectAttendanceLogList(attendanceLog);
        attendanceLogList.forEach(item->{
            Student student = studentMapper.selectStudentById(item.getStudentId());
            if (student != null) {
                item.setStudentName(student.getName());
                item.setAge(student.getAge());
                item.setStudentNo(student.getStudentNo());
            }
            ClassInfo classInfo = classInfoMapper.selectClassInfoById(item.getClassId());
            if (classInfo != null) {
                item.setClassName(classInfo.getClassName());
            }
        });

        return attendanceLogList;
    }

    /**
     * 新增入离园日志信息
     * 
     * @param attendanceLog 入离园日志信息
     * @return 结果
     */
    @Override
    public int insertAttendanceLog(AttendanceLog attendanceLog)
    {
        attendanceLog.setCreateTime(DateUtils.getNowDate());
        return attendanceLogMapper.insertAttendanceLog(attendanceLog);
    }

    /**
     * 修改入离园日志信息
     * 
     * @param attendanceLog 入离园日志信息
     * @return 结果
     */
    @Override
    public int updateAttendanceLog(AttendanceLog attendanceLog)
    {
        return attendanceLogMapper.updateAttendanceLog(attendanceLog);
    }

    /**
     * 批量删除入离园日志信息
     * 
     * @param ids 需要删除的入离园日志信息主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceLogByIds(Long[] ids)
    {
        return attendanceLogMapper.deleteAttendanceLogByIds(ids);
    }

    /**
     * 删除入离园日志信息信息
     * 
     * @param id 入离园日志信息主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceLogById(Long id)
    {
        return attendanceLogMapper.deleteAttendanceLogById(id);
    }
}
